import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Search from '../views/product/searchProduct.vue'
import Register from '../views/user/register.vue'
import Login from '../views/user/login.vue'
import Clause from '../views/user/clause.vue'
import Classify from '../views/product/classify.vue'
import ProductDetail from '../views/product/productDetail.vue'
import ShopCar from '../views/shop/shopCar.vue'
import Order from '../views/order/order.vue'
import Addaddress from '../views/address/addAddress.vue'
import AddressList from '../views/address/addressList.vue'
import BaiduMap from '../views/address/baiduMap.vue'
import OrderPay from '../views/order/orderPay.vue'
import PaySuccess from '../views/order/paySuccess.vue'
import OrderInfo from '../views/order/orderInfo.vue'
import Logistics from '../views/order/logistics.vue'
import AllOrder from '../views/order/allOrder.vue'
import User from '../views/user/user.vue'
import UserSetting from '../views/user/userSetting.vue'
import Setting from '../views/user/setting.vue'
import SetPassword from '../views/user/setPassword.vue'
import SetAvatar from '../views/user/settingAvatar.vue'
import UserSuggest from '../views/user/userSuggest.vue'
import Yiqin from '../views/public/yiqin.vue'
import MapMessage from '../views/public/map.vue'
import WorldMap from '../views/public/worldMap.vue'
import Active from '../views/public/active.vue'
import InfoCollection from '../views/public/infoCollection.vue'
import BotUi from '../views/public/botUi.vue'
import DoctorBot from '../views/public/doctorBot.vue'
import Face from '@/views/user/face.vue'
import LoginHome from '@/views/user/loginHome.vue'
Vue.use(VueRouter)

const routes = [
{
  path: '/',
  redirect: '/home'
},
{
  path: '/home',
  name: 'home',
  component: Home,
  meta: { isPublic: true }
},
{
  path: '/search',
  name: 'search',
  component: Search,
  meta: { isPublic: true }
},
{
  path: '/register',
  name: 'register',
  component: Register,
  meta: { isPublic: true }
},
{
  path: '/login',
  name: 'login',
  component: Login,
  meta: { isPublic: true }
},
{
  path: '/loginHome',
  name: 'loginHome',
  component: LoginHome,
  meta: { isPublic: true }
},
{
  path: '/clause',
  name: 'clause',
  component: Clause,
  meta: { isPublic: true }
},
{
  path: '/classify/:keyWord?',
  name: 'classify',
  component: Classify,
  props: true,
  // meta: { isPublic: true }
},
{
  path: '/productDetail/:id?',
  name: 'productDetail',
  component: ProductDetail,
  props: true,
  
},
{
  path: '/shopCar',
  name: 'shopCar',
  component: ShopCar,
},
{
  path: '/order',
  name: 'order',
  component: Order,

},
//这里需要修改  有警告
// {
//   path: "/addAddress",
//   name: 'addAddress',
//   component: Addaddress,
// },
{
  path: "/addAddress/:id?",
  name: 'addAddress',
  component: Addaddress,
  props: true,
  
},
{
  path: '/addressList',
  name: 'addressList',
  component: AddressList,
},
{
  path: '/baiduMap/:id?',
  name: 'baiduMap',
  component: BaiduMap,
  props: true,
},
{
  path: '/orderPay/:id?',
  name: 'orderPay',
  component: OrderPay,
  props: true,
},
{
  path: '/paySuccess/:id?',
  name: 'paySuccess',
  component: PaySuccess,
  props: true,
},
{
  path: '/order/orderInfo/:id?',
  name: 'orderInfo',
  component: OrderInfo,
  props: true,
},
{
  path: '/order/logistics/:id?',
  name: 'logistics',
  component: Logistics,
  props: true,
},
{
  path: '/order/allOrder/:type?',
  name: 'allOrder',
  component: AllOrder,
  props: true,
},
{
  path: '/user',
  name: 'user',
  component: User,
  
},
{
  path: '/user/userSetting',
  name: 'userSetting',
  component: UserSetting,

},
{
  path: '/user/setting',
  name: 'setting',
  component: Setting,

},
{
  path: '/user/userSetting/setPassword',
  name: 'setPassword',
  component: SetPassword,
},
{
  path: '/user/userSetting/setAvatar',
  name: 'setAvatar',
  component: SetAvatar,
},
{
  path: '/user/userSuggest',
  name: 'userSuggest',
  component: UserSuggest,
  
},
{
  path: '/infoCollection',
  name: 'infoCollection',
  component: InfoCollection,
  
},
{
  path: '/yiqin',
  name: 'yiqin',
  component: Yiqin,
  redirect: '/yiqin/map',
  children: [
      {path: "/yiqin/map",component: MapMessage,meta: { isPublic: true }},
      {path: "/yiqin/worldMap",component: WorldMap,meta: { isPublic: true }},
      {path: "/yiqin/active",component: Active,meta: { isPublic: true }},
  ],
  meta: { isPublic: true }

},
{
  path: '/botUi',
  name: 'botUi',
  component: BotUi,
  
},
{
  path: '/doctorBot',
  name: 'doctorBot',
  component: DoctorBot,
  
},
{
  path: '/faceRegist/:user',
  name: 'face',
  component: Face,
  props: true
},
{
  path: '/faceLigon',
  name: 'face',
  component: Face,
  meta: { isPublic: true }
},

]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

//路由守卫 表示在你每次切换路由是时候要做什么
router.beforeEach((to,from,next) => {
  //如果定义的 meta.isPublic 
  if (!to.meta.isPublic && !localStorage.token) {
    return next('/loginHome')
  }
  next()
})

export default router
